<template>
  <el-form class="login-form" status-icon :rules="loginRules" ref="loginForm" :model="loginForm" label-width="0">
    <el-form-item prop="username" class="user-name">
      <!-- <el-input
        size="small"
        @keyup.enter.native="handleLogin"
        v-model="loginForm.username"
        auto-complete="off"
        :placeholder="$t('login.username')"
      >
        <i slot="prefix" class="icon-yonghu"></i>
      </el-input> -->
      <el-input @keyup.enter.native="handleLogin" auto-complete="off" v-model="loginForm.username"
        placeholder="请输入账号">
      </el-input>
      <img :src="require('@/assets/imgs/login/user.png')" />
    </el-form-item>
    <el-form-item prop="password" class="psd">
      <!-- <el-input
        size="small"
        @keyup.enter.native="handleLogin"
        :type="passwordType"
        v-model="loginForm.password"
        auto-complete="off"
        :placeholder="$t('login.password')"
      >
        <i
          class="el-icon-view el-input__icon" 
		      style="font-size: 18px;"
          slot="suffix"
          @click="showPassword"
        ></i>
        <i slot="prefix" class="icon-mima"></i>
      </el-input> -->
      <el-input @keyup.enter.native="handleLogin" :type="passwordType" v-model="loginForm.password"
        auto-complete="off" placeholder="请输入密码">
        <i class="el-icon-view el-input__icon" style="font-size: 18px;" slot="suffix" @click="showPassword"></i>
      </el-input>
      <img :src="require('@/assets/imgs/login/psd.png')" />
     
    </el-form-item>
    <el-form-item>
       <div class="agenPwd"><span @click="$parent.forgetPassword()">忘记密码</span></div>
    </el-form-item>
    <el-form-item>
      <!-- <el-button
        type="primary"
        size="small"
        @click.native.prevent="handleLogin"
        class="login-submit"
        >{{ $t("login.submit") }}</el-button
      > -->
      <el-button @click.native.prevent="handleLogin" class="login-btn" type="primary">登录</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "userlogin",
  data() {
    return {
      loginForm: {
        username: "",
        password: "",
      },
      checked: false,
      loginRules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
        ],
      },
      passwordType: "password",
    };
  },
  created() {
  },
  mounted() { },
  computed: {
    ...mapGetters(["tagWel"]),
  },
  props: [],
  methods: {
    showPassword() {
      this.passwordType === ""
        ? (this.passwordType = "password")
        : (this.passwordType = "");
    },
    handleLogin() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.$store.dispatch("LoginByUsername", this.loginForm).then(() => {
            //登录前是否有 登录返回地址
            let loginBackPath = window.localStorage.getItem('loginBackPath');
            if (loginBackPath) {
              this.$router.push({ path: loginBackPath });
              window.localStorage.setItem('loginBackPath', "");//登录返回地址置空
            } else {
              for (var i = 0; i < this.tagWel.length; i++) {
                this.$router.push({ path: this.tagWel[i].value });
              }
            }
          });
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
::v-deep .agenPwd{
   font-size: 14px;
   color: #0063f5;
   text-align:right;
   span{
    cursor: pointer;
   }
}
.msg-text {
  display: block;
  width: 60px;
  font-size: 12px;
  text-align: center;
  cursor: pointer;
}
.el-form-item {
    margin-top: 0;
    margin-bottom: 40px !important;
}
.login-btn {
  width: 100%;
  height: 50px;
  font-size: 16px;
  background-color: #4371E4;
  border-color: #4371E4;
 
}
::v-deep .login-btn:hover{
  opacity: .9;
}
.psd{
  margin-bottom: 13px!important;
}
@media screen and (max-width: 1440px) {
    .el-form-item {
        margin-bottom: 20px !important;
    }

   
   
}
.user-name img,
.psd img{
  position: absolute;
  top: 10px;
  left: 30px;
  width: 26px;
  height: 26px;
}
.psd img{
  width: 24px;
  height: 29px;
}
.psd ::v-deep .el-input__suffix{
  top: 3px;
  right: 16px;
}
</style>
